home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4551 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  50 lines

  1. Path: hilbert.dnai.com!usenet
  2. From: Victor Bazarov <vbazarov@imsisoft.com>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: C type question
  5. Date: Mon, 05 Feb 1996 11:45:28 -0800
  6. Organization: IMSI
  7. Message-ID: <31165E58.104B@imsisoft.com>
  8. References: <Pine.SUN.3.91.960202131027.20090A-100000@sun19.cs.cuhk.hk>
  9. NNTP-Posting-Host: 204.182.61.84
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0b6a (Win95; I)
  14.  
  15. Cheung ming wai wrote:
  16. > Hi,
  17. > I've some problems about my following program:
  18. > The program should be run under PC.
  19. > =========
  20. > /* program to find the smallest +ve number */
  21. > #include <stdio.h>
  22. > main(void)
  23. > {
  24. >    long double u, v;
  25. >    u = v = 0.5;
  26. >    while((1+u) > 1)  {
  27. >       v = u;
  28. >       u /= 2;
  29. >    }
  30. >    printf("The smallest number (1+u)>1 is: %e.\n", v);
  31.  
  32. The problem is that some compilers expect "%le" for double values.
  33. Their printf accepts %e, %f, or %g as formats for float values, not
  34. double. So try %le.
  35.  
  36. >    return 0;
  37. > }
  38. > ================
  39. > The result output is somewhat not true!? 4.???e-3XX
  40. > But if I use C++ cout as output, the ans is 4.????e-19
  41. > Do I get something wrong in the printf()?
  42. > What is the argument used for long double? %e? %g? %lf?
  43.  
  44. Victor.
  45.